<?php

class TagManageController extends Controller
{
    public function filters()
    {
        return array(
            'accessControl', // perform access control for CRUD operations
        );
    }

    public function accessRules()
    {
        return array(

            array('allow', // allow authenticated user to perform 'create' and 'update' actions
                'actions'=>array('add','getlist','delete'),
                'users'=>array('admin'),
            ),
            array('deny',  // deny all users
                'users'=>array('*'),
            ),
        );
    }

	/**
	 * Declares class-based actions.
	 */
	public function actions()
	{
		return array(
		);
	}

    public function actionAdd()
    {

        $query = array(
            'conditions' => array(
                'name_zn'=>array('=='=>$_POST["name_zn"])
               // 'channel'=>array('=='=>constant("channel_homepage"))
            ),
        );

        if(count(Tag::model()->findAll($query))>0)
        {
            header("HTTP/1.0 400 Bad Request");
            die();
        }
        $brand = new Tag();
        $brand->name_zn = $_POST["name_zn"];
        $brand->name_en = $_POST["name_en"];
        $brand->save(false);
    }


    /**
     * 获得版本信息
     */
    public function actionGetList($iDisplayStart=0,$iDisplayLength=10)
    {
        $result = Tag::model()->findAll();
        foreach ($result as $key => $value) {
            $value->_id = (string)$value->_id;
            unset($value->id);
        }
        echoStringToMobile(json_encode($result));
    }

    public function actionDelete($id)
    {
        Tag::model()->deleteByPk(new MongoId($id));
    }
}